Importing the libraries:
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.filterwarnings("ignore")
Highlighting the maximum values of each attribute in the data set
df=pd.read_csv("2019.csv")
df.head()
def highlight_max(s):
is_max = s == s.max()
return ['background-color: limegreen' if v else '' for v in is_max]
df.style.apply(highlight_max)
| Overall rank | Country or region | Score | GDP per capita | Social support | Healthy life expectancy | Freedom to make life choices | Generosity | Perceptions of corruption | |
|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | Finland | 7.769000 | 1.340000 | 1.587000 | 0.986000 | 0.596000 | 0.153000 | 0.393000 |
| 1 | 2 | Denmark | 7.600000 | 1.383000 | 1.573000 | 0.996000 | 0.592000 | 0.252000 | 0.410000 |
| 2 | 3 | Norway | 7.554000 | 1.488000 | 1.582000 | 1.028000 | 0.603000 | 0.271000 | 0.341000 |
| 3 | 4 | Iceland | 7.494000 | 1.380000 | 1.624000 | 1.026000 | 0.591000 | 0.354000 | 0.118000 |
| 4 | 5 | Netherlands | 7.488000 | 1.396000 | 1.522000 | 0.999000 | 0.557000 | 0.322000 | 0.298000 |
| 5 | 6 | Switzerland | 7.480000 | 1.452000 | 1.526000 | 1.052000 | 0.572000 | 0.263000 | 0.343000 |
| 6 | 7 | Sweden | 7.343000 | 1.387000 | 1.487000 | 1.009000 | 0.574000 | 0.267000 | 0.373000 |
| 7 | 8 | New Zealand | 7.307000 | 1.303000 | 1.557000 | 1.026000 | 0.585000 | 0.330000 | 0.380000 |
| 8 | 9 | Canada | 7.278000 | 1.365000 | 1.505000 | 1.039000 | 0.584000 | 0.285000 | 0.308000 |
| 9 | 10 | Austria | 7.246000 | 1.376000 | 1.475000 | 1.016000 | 0.532000 | 0.244000 | 0.226000 |
| 10 | 11 | Australia | 7.228000 | 1.372000 | 1.548000 | 1.036000 | 0.557000 | 0.332000 | 0.290000 |
| 11 | 12 | Costa Rica | 7.167000 | 1.034000 | 1.441000 | 0.963000 | 0.558000 | 0.144000 | 0.093000 |
| 12 | 13 | Israel | 7.139000 | 1.276000 | 1.455000 | 1.029000 | 0.371000 | 0.261000 | 0.082000 |
| 13 | 14 | Luxembourg | 7.090000 | 1.609000 | 1.479000 | 1.012000 | 0.526000 | 0.194000 | 0.316000 |
| 14 | 15 | United Kingdom | 7.054000 | 1.333000 | 1.538000 | 0.996000 | 0.450000 | 0.348000 | 0.278000 |
| 15 | 16 | Ireland | 7.021000 | 1.499000 | 1.553000 | 0.999000 | 0.516000 | 0.298000 | 0.310000 |
| 16 | 17 | Germany | 6.985000 | 1.373000 | 1.454000 | 0.987000 | 0.495000 | 0.261000 | 0.265000 |
| 17 | 18 | Belgium | 6.923000 | 1.356000 | 1.504000 | 0.986000 | 0.473000 | 0.160000 | 0.210000 |
| 18 | 19 | United States | 6.892000 | 1.433000 | 1.457000 | 0.874000 | 0.454000 | 0.280000 | 0.128000 |
| 19 | 20 | Czech Republic | 6.852000 | 1.269000 | 1.487000 | 0.920000 | 0.457000 | 0.046000 | 0.036000 |
| 20 | 21 | United Arab Emirates | 6.825000 | 1.503000 | 1.310000 | 0.825000 | 0.598000 | 0.262000 | 0.182000 |
| 21 | 22 | Malta | 6.726000 | 1.300000 | 1.520000 | 0.999000 | 0.564000 | 0.375000 | 0.151000 |
| 22 | 23 | Mexico | 6.595000 | 1.070000 | 1.323000 | 0.861000 | 0.433000 | 0.074000 | 0.073000 |
| 23 | 24 | France | 6.592000 | 1.324000 | 1.472000 | 1.045000 | 0.436000 | 0.111000 | 0.183000 |
| 24 | 25 | Taiwan | 6.446000 | 1.368000 | 1.430000 | 0.914000 | 0.351000 | 0.242000 | 0.097000 |
| 25 | 26 | Chile | 6.444000 | 1.159000 | 1.369000 | 0.920000 | 0.357000 | 0.187000 | 0.056000 |
| 26 | 27 | Guatemala | 6.436000 | 0.800000 | 1.269000 | 0.746000 | 0.535000 | 0.175000 | 0.078000 |
| 27 | 28 | Saudi Arabia | 6.375000 | 1.403000 | 1.357000 | 0.795000 | 0.439000 | 0.080000 | 0.132000 |
| 28 | 29 | Qatar | 6.374000 | 1.684000 | 1.313000 | 0.871000 | 0.555000 | 0.220000 | 0.167000 |
| 29 | 30 | Spain | 6.354000 | 1.286000 | 1.484000 | 1.062000 | 0.362000 | 0.153000 | 0.079000 |
| 30 | 31 | Panama | 6.321000 | 1.149000 | 1.442000 | 0.910000 | 0.516000 | 0.109000 | 0.054000 |
| 31 | 32 | Brazil | 6.300000 | 1.004000 | 1.439000 | 0.802000 | 0.390000 | 0.099000 | 0.086000 |
| 32 | 33 | Uruguay | 6.293000 | 1.124000 | 1.465000 | 0.891000 | 0.523000 | 0.127000 | 0.150000 |
| 33 | 34 | Singapore | 6.262000 | 1.572000 | 1.463000 | 1.141000 | 0.556000 | 0.271000 | 0.453000 |
| 34 | 35 | El Salvador | 6.253000 | 0.794000 | 1.242000 | 0.789000 | 0.430000 | 0.093000 | 0.074000 |
| 35 | 36 | Italy | 6.223000 | 1.294000 | 1.488000 | 1.039000 | 0.231000 | 0.158000 | 0.030000 |
| 36 | 37 | Bahrain | 6.199000 | 1.362000 | 1.368000 | 0.871000 | 0.536000 | 0.255000 | 0.110000 |
| 37 | 38 | Slovakia | 6.198000 | 1.246000 | 1.504000 | 0.881000 | 0.334000 | 0.121000 | 0.014000 |
| 38 | 39 | Trinidad & Tobago | 6.192000 | 1.231000 | 1.477000 | 0.713000 | 0.489000 | 0.185000 | 0.016000 |
| 39 | 40 | Poland | 6.182000 | 1.206000 | 1.438000 | 0.884000 | 0.483000 | 0.117000 | 0.050000 |
| 40 | 41 | Uzbekistan | 6.174000 | 0.745000 | 1.529000 | 0.756000 | 0.631000 | 0.322000 | 0.240000 |
| 41 | 42 | Lithuania | 6.149000 | 1.238000 | 1.515000 | 0.818000 | 0.291000 | 0.043000 | 0.042000 |
| 42 | 43 | Colombia | 6.125000 | 0.985000 | 1.410000 | 0.841000 | 0.470000 | 0.099000 | 0.034000 |
| 43 | 44 | Slovenia | 6.118000 | 1.258000 | 1.523000 | 0.953000 | 0.564000 | 0.144000 | 0.057000 |
| 44 | 45 | Nicaragua | 6.105000 | 0.694000 | 1.325000 | 0.835000 | 0.435000 | 0.200000 | 0.127000 |
| 45 | 46 | Kosovo | 6.100000 | 0.882000 | 1.232000 | 0.758000 | 0.489000 | 0.262000 | 0.006000 |
| 46 | 47 | Argentina | 6.086000 | 1.092000 | 1.432000 | 0.881000 | 0.471000 | 0.066000 | 0.050000 |
| 47 | 48 | Romania | 6.070000 | 1.162000 | 1.232000 | 0.825000 | 0.462000 | 0.083000 | 0.005000 |
| 48 | 49 | Cyprus | 6.046000 | 1.263000 | 1.223000 | 1.042000 | 0.406000 | 0.190000 | 0.041000 |
| 49 | 50 | Ecuador | 6.028000 | 0.912000 | 1.312000 | 0.868000 | 0.498000 | 0.126000 | 0.087000 |
| 50 | 51 | Kuwait | 6.021000 | 1.500000 | 1.319000 | 0.808000 | 0.493000 | 0.142000 | 0.097000 |
| 51 | 52 | Thailand | 6.008000 | 1.050000 | 1.409000 | 0.828000 | 0.557000 | 0.359000 | 0.028000 |
| 52 | 53 | Latvia | 5.940000 | 1.187000 | 1.465000 | 0.812000 | 0.264000 | 0.075000 | 0.064000 |
| 53 | 54 | South Korea | 5.895000 | 1.301000 | 1.219000 | 1.036000 | 0.159000 | 0.175000 | 0.056000 |
| 54 | 55 | Estonia | 5.893000 | 1.237000 | 1.528000 | 0.874000 | 0.495000 | 0.103000 | 0.161000 |
| 55 | 56 | Jamaica | 5.890000 | 0.831000 | 1.478000 | 0.831000 | 0.490000 | 0.107000 | 0.028000 |
| 56 | 57 | Mauritius | 5.888000 | 1.120000 | 1.402000 | 0.798000 | 0.498000 | 0.215000 | 0.060000 |
| 57 | 58 | Japan | 5.886000 | 1.327000 | 1.419000 | 1.088000 | 0.445000 | 0.069000 | 0.140000 |
| 58 | 59 | Honduras | 5.860000 | 0.642000 | 1.236000 | 0.828000 | 0.507000 | 0.246000 | 0.078000 |
| 59 | 60 | Kazakhstan | 5.809000 | 1.173000 | 1.508000 | 0.729000 | 0.410000 | 0.146000 | 0.096000 |
| 60 | 61 | Bolivia | 5.779000 | 0.776000 | 1.209000 | 0.706000 | 0.511000 | 0.137000 | 0.064000 |
| 61 | 62 | Hungary | 5.758000 | 1.201000 | 1.410000 | 0.828000 | 0.199000 | 0.081000 | 0.020000 |
| 62 | 63 | Paraguay | 5.743000 | 0.855000 | 1.475000 | 0.777000 | 0.514000 | 0.184000 | 0.080000 |
| 63 | 64 | Northern Cyprus | 5.718000 | 1.263000 | 1.252000 | 1.042000 | 0.417000 | 0.191000 | 0.162000 |
| 64 | 65 | Peru | 5.697000 | 0.960000 | 1.274000 | 0.854000 | 0.455000 | 0.083000 | 0.027000 |
| 65 | 66 | Portugal | 5.693000 | 1.221000 | 1.431000 | 0.999000 | 0.508000 | 0.047000 | 0.025000 |
| 66 | 67 | Pakistan | 5.653000 | 0.677000 | 0.886000 | 0.535000 | 0.313000 | 0.220000 | 0.098000 |
| 67 | 68 | Russia | 5.648000 | 1.183000 | 1.452000 | 0.726000 | 0.334000 | 0.082000 | 0.031000 |
| 68 | 69 | Philippines | 5.631000 | 0.807000 | 1.293000 | 0.657000 | 0.558000 | 0.117000 | 0.107000 |
| 69 | 70 | Serbia | 5.603000 | 1.004000 | 1.383000 | 0.854000 | 0.282000 | 0.137000 | 0.039000 |
| 70 | 71 | Moldova | 5.529000 | 0.685000 | 1.328000 | 0.739000 | 0.245000 | 0.181000 | 0.000000 |
| 71 | 72 | Libya | 5.525000 | 1.044000 | 1.303000 | 0.673000 | 0.416000 | 0.133000 | 0.152000 |
| 72 | 73 | Montenegro | 5.523000 | 1.051000 | 1.361000 | 0.871000 | 0.197000 | 0.142000 | 0.080000 |
| 73 | 74 | Tajikistan | 5.467000 | 0.493000 | 1.098000 | 0.718000 | 0.389000 | 0.230000 | 0.144000 |
| 74 | 75 | Croatia | 5.432000 | 1.155000 | 1.266000 | 0.914000 | 0.296000 | 0.119000 | 0.022000 |
| 75 | 76 | Hong Kong | 5.430000 | 1.438000 | 1.277000 | 1.122000 | 0.440000 | 0.258000 | 0.287000 |
| 76 | 77 | Dominican Republic | 5.425000 | 1.015000 | 1.401000 | 0.779000 | 0.497000 | 0.113000 | 0.101000 |
| 77 | 78 | Bosnia and Herzegovina | 5.386000 | 0.945000 | 1.212000 | 0.845000 | 0.212000 | 0.263000 | 0.006000 |
| 78 | 79 | Turkey | 5.373000 | 1.183000 | 1.360000 | 0.808000 | 0.195000 | 0.083000 | 0.106000 |
| 79 | 80 | Malaysia | 5.339000 | 1.221000 | 1.171000 | 0.828000 | 0.508000 | 0.260000 | 0.024000 |
| 80 | 81 | Belarus | 5.323000 | 1.067000 | 1.465000 | 0.789000 | 0.235000 | 0.094000 | 0.142000 |
| 81 | 82 | Greece | 5.287000 | 1.181000 | 1.156000 | 0.999000 | 0.067000 | 0.000000 | 0.034000 |
| 82 | 83 | Mongolia | 5.285000 | 0.948000 | 1.531000 | 0.667000 | 0.317000 | 0.235000 | 0.038000 |
| 83 | 84 | North Macedonia | 5.274000 | 0.983000 | 1.294000 | 0.838000 | 0.345000 | 0.185000 | 0.034000 |
| 84 | 85 | Nigeria | 5.265000 | 0.696000 | 1.111000 | 0.245000 | 0.426000 | 0.215000 | 0.041000 |
| 85 | 86 | Kyrgyzstan | 5.261000 | 0.551000 | 1.438000 | 0.723000 | 0.508000 | 0.300000 | 0.023000 |
| 86 | 87 | Turkmenistan | 5.247000 | 1.052000 | 1.538000 | 0.657000 | 0.394000 | 0.244000 | 0.028000 |
| 87 | 88 | Algeria | 5.211000 | 1.002000 | 1.160000 | 0.785000 | 0.086000 | 0.073000 | 0.114000 |
| 88 | 89 | Morocco | 5.208000 | 0.801000 | 0.782000 | 0.782000 | 0.418000 | 0.036000 | 0.076000 |
| 89 | 90 | Azerbaijan | 5.208000 | 1.043000 | 1.147000 | 0.769000 | 0.351000 | 0.035000 | 0.182000 |
| 90 | 91 | Lebanon | 5.197000 | 0.987000 | 1.224000 | 0.815000 | 0.216000 | 0.166000 | 0.027000 |
| 91 | 92 | Indonesia | 5.192000 | 0.931000 | 1.203000 | 0.660000 | 0.491000 | 0.498000 | 0.028000 |
| 92 | 93 | China | 5.191000 | 1.029000 | 1.125000 | 0.893000 | 0.521000 | 0.058000 | 0.100000 |
| 93 | 94 | Vietnam | 5.175000 | 0.741000 | 1.346000 | 0.851000 | 0.543000 | 0.147000 | 0.073000 |
| 94 | 95 | Bhutan | 5.082000 | 0.813000 | 1.321000 | 0.604000 | 0.457000 | 0.370000 | 0.167000 |
| 95 | 96 | Cameroon | 5.044000 | 0.549000 | 0.910000 | 0.331000 | 0.381000 | 0.187000 | 0.037000 |
| 96 | 97 | Bulgaria | 5.011000 | 1.092000 | 1.513000 | 0.815000 | 0.311000 | 0.081000 | 0.004000 |
| 97 | 98 | Ghana | 4.996000 | 0.611000 | 0.868000 | 0.486000 | 0.381000 | 0.245000 | 0.040000 |
| 98 | 99 | Ivory Coast | 4.944000 | 0.569000 | 0.808000 | 0.232000 | 0.352000 | 0.154000 | 0.090000 |
| 99 | 100 | Nepal | 4.913000 | 0.446000 | 1.226000 | 0.677000 | 0.439000 | 0.285000 | 0.089000 |
| 100 | 101 | Jordan | 4.906000 | 0.837000 | 1.225000 | 0.815000 | 0.383000 | 0.110000 | 0.130000 |
| 101 | 102 | Benin | 4.883000 | 0.393000 | 0.437000 | 0.397000 | 0.349000 | 0.175000 | 0.082000 |
| 102 | 103 | Congo (Brazzaville) | 4.812000 | 0.673000 | 0.799000 | 0.508000 | 0.372000 | 0.105000 | 0.093000 |
| 103 | 104 | Gabon | 4.799000 | 1.057000 | 1.183000 | 0.571000 | 0.295000 | 0.043000 | 0.055000 |
| 104 | 105 | Laos | 4.796000 | 0.764000 | 1.030000 | 0.551000 | 0.547000 | 0.266000 | 0.164000 |
| 105 | 106 | South Africa | 4.722000 | 0.960000 | 1.351000 | 0.469000 | 0.389000 | 0.130000 | 0.055000 |
| 106 | 107 | Albania | 4.719000 | 0.947000 | 0.848000 | 0.874000 | 0.383000 | 0.178000 | 0.027000 |
| 107 | 108 | Venezuela | 4.707000 | 0.960000 | 1.427000 | 0.805000 | 0.154000 | 0.064000 | 0.047000 |
| 108 | 109 | Cambodia | 4.700000 | 0.574000 | 1.122000 | 0.637000 | 0.609000 | 0.232000 | 0.062000 |
| 109 | 110 | Palestinian Territories | 4.696000 | 0.657000 | 1.247000 | 0.672000 | 0.225000 | 0.103000 | 0.066000 |
| 110 | 111 | Senegal | 4.681000 | 0.450000 | 1.134000 | 0.571000 | 0.292000 | 0.153000 | 0.072000 |
| 111 | 112 | Somalia | 4.668000 | 0.000000 | 0.698000 | 0.268000 | 0.559000 | 0.243000 | 0.270000 |
| 112 | 113 | Namibia | 4.639000 | 0.879000 | 1.313000 | 0.477000 | 0.401000 | 0.070000 | 0.056000 |
| 113 | 114 | Niger | 4.628000 | 0.138000 | 0.774000 | 0.366000 | 0.318000 | 0.188000 | 0.102000 |
| 114 | 115 | Burkina Faso | 4.587000 | 0.331000 | 1.056000 | 0.380000 | 0.255000 | 0.177000 | 0.113000 |
| 115 | 116 | Armenia | 4.559000 | 0.850000 | 1.055000 | 0.815000 | 0.283000 | 0.095000 | 0.064000 |
| 116 | 117 | Iran | 4.548000 | 1.100000 | 0.842000 | 0.785000 | 0.305000 | 0.270000 | 0.125000 |
| 117 | 118 | Guinea | 4.534000 | 0.380000 | 0.829000 | 0.375000 | 0.332000 | 0.207000 | 0.086000 |
| 118 | 119 | Georgia | 4.519000 | 0.886000 | 0.666000 | 0.752000 | 0.346000 | 0.043000 | 0.164000 |
| 119 | 120 | Gambia | 4.516000 | 0.308000 | 0.939000 | 0.428000 | 0.382000 | 0.269000 | 0.167000 |
| 120 | 121 | Kenya | 4.509000 | 0.512000 | 0.983000 | 0.581000 | 0.431000 | 0.372000 | 0.053000 |
| 121 | 122 | Mauritania | 4.490000 | 0.570000 | 1.167000 | 0.489000 | 0.066000 | 0.106000 | 0.088000 |
| 122 | 123 | Mozambique | 4.466000 | 0.204000 | 0.986000 | 0.390000 | 0.494000 | 0.197000 | 0.138000 |
| 123 | 124 | Tunisia | 4.461000 | 0.921000 | 1.000000 | 0.815000 | 0.167000 | 0.059000 | 0.055000 |
| 124 | 125 | Bangladesh | 4.456000 | 0.562000 | 0.928000 | 0.723000 | 0.527000 | 0.166000 | 0.143000 |
| 125 | 126 | Iraq | 4.437000 | 1.043000 | 0.980000 | 0.574000 | 0.241000 | 0.148000 | 0.089000 |
| 126 | 127 | Congo (Kinshasa) | 4.418000 | 0.094000 | 1.125000 | 0.357000 | 0.269000 | 0.212000 | 0.053000 |
| 127 | 128 | Mali | 4.390000 | 0.385000 | 1.105000 | 0.308000 | 0.327000 | 0.153000 | 0.052000 |
| 128 | 129 | Sierra Leone | 4.374000 | 0.268000 | 0.841000 | 0.242000 | 0.309000 | 0.252000 | 0.045000 |
| 129 | 130 | Sri Lanka | 4.366000 | 0.949000 | 1.265000 | 0.831000 | 0.470000 | 0.244000 | 0.047000 |
| 130 | 131 | Myanmar | 4.360000 | 0.710000 | 1.181000 | 0.555000 | 0.525000 | 0.566000 | 0.172000 |
| 131 | 132 | Chad | 4.350000 | 0.350000 | 0.766000 | 0.192000 | 0.174000 | 0.198000 | 0.078000 |
| 132 | 133 | Ukraine | 4.332000 | 0.820000 | 1.390000 | 0.739000 | 0.178000 | 0.187000 | 0.010000 |
| 133 | 134 | Ethiopia | 4.286000 | 0.336000 | 1.033000 | 0.532000 | 0.344000 | 0.209000 | 0.100000 |
| 134 | 135 | Swaziland | 4.212000 | 0.811000 | 1.149000 | 0.000000 | 0.313000 | 0.074000 | 0.135000 |
| 135 | 136 | Uganda | 4.189000 | 0.332000 | 1.069000 | 0.443000 | 0.356000 | 0.252000 | 0.060000 |
| 136 | 137 | Egypt | 4.166000 | 0.913000 | 1.039000 | 0.644000 | 0.241000 | 0.076000 | 0.067000 |
| 137 | 138 | Zambia | 4.107000 | 0.578000 | 1.058000 | 0.426000 | 0.431000 | 0.247000 | 0.087000 |
| 138 | 139 | Togo | 4.085000 | 0.275000 | 0.572000 | 0.410000 | 0.293000 | 0.177000 | 0.085000 |
| 139 | 140 | India | 4.015000 | 0.755000 | 0.765000 | 0.588000 | 0.498000 | 0.200000 | 0.085000 |
| 140 | 141 | Liberia | 3.975000 | 0.073000 | 0.922000 | 0.443000 | 0.370000 | 0.233000 | 0.033000 |
| 141 | 142 | Comoros | 3.973000 | 0.274000 | 0.757000 | 0.505000 | 0.142000 | 0.275000 | 0.078000 |
| 142 | 143 | Madagascar | 3.933000 | 0.274000 | 0.916000 | 0.555000 | 0.148000 | 0.169000 | 0.041000 |
| 143 | 144 | Lesotho | 3.802000 | 0.489000 | 1.169000 | 0.168000 | 0.359000 | 0.107000 | 0.093000 |
| 144 | 145 | Burundi | 3.775000 | 0.046000 | 0.447000 | 0.380000 | 0.220000 | 0.176000 | 0.180000 |
| 145 | 146 | Zimbabwe | 3.663000 | 0.366000 | 1.114000 | 0.433000 | 0.361000 | 0.151000 | 0.089000 |
| 146 | 147 | Haiti | 3.597000 | 0.323000 | 0.688000 | 0.449000 | 0.026000 | 0.419000 | 0.110000 |
| 147 | 148 | Botswana | 3.488000 | 1.041000 | 1.145000 | 0.538000 | 0.455000 | 0.025000 | 0.100000 |
| 148 | 149 | Syria | 3.462000 | 0.619000 | 0.378000 | 0.440000 | 0.013000 | 0.331000 | 0.141000 |
| 149 | 150 | Malawi | 3.410000 | 0.191000 | 0.560000 | 0.495000 | 0.443000 | 0.218000 | 0.089000 |
| 150 | 151 | Yemen | 3.380000 | 0.287000 | 1.163000 | 0.463000 | 0.143000 | 0.108000 | 0.077000 |
| 151 | 152 | Rwanda | 3.334000 | 0.359000 | 0.711000 | 0.614000 | 0.555000 | 0.217000 | 0.411000 |
| 152 | 153 | Tanzania | 3.231000 | 0.476000 | 0.885000 | 0.499000 | 0.417000 | 0.276000 | 0.147000 |
| 153 | 154 | Afghanistan | 3.203000 | 0.350000 | 0.517000 | 0.361000 | 0.000000 | 0.158000 | 0.025000 |
| 154 | 155 | Central African Republic | 3.083000 | 0.026000 | 0.000000 | 0.105000 | 0.225000 | 0.235000 | 0.035000 |
| 155 | 156 | South Sudan | 2.853000 | 0.306000 | 0.575000 | 0.295000 | 0.010000 | 0.202000 | 0.091000 |
df.shape
(156, 9)
Plotting pairwise relationships in the data set
import seaborn as sns
sns.pairplot(df)
<seaborn.axisgrid.PairGrid at 0x14085911640>
Top 10 countries for each attribute
fig, axes = plt.subplots(nrows=2, ncols=2,constrained_layout=True,figsize=(12,8))
sns.barplot(x='GDP per capita',y='Country or region',data=df.nlargest(10,'GDP per capita'),ax=axes[0,0],palette="Blues_d")
sns.barplot(x='Social support' ,y='Country or region',data=df.nlargest(10,'Social support'),ax=axes[0,1],palette="YlGn")
sns.barplot(x='Healthy life expectancy' ,y='Country or region',data=df.nlargest(10,'Healthy life expectancy'),ax=axes[1,0],palette='OrRd')
sns.barplot(x='Freedom to make life choices' ,y='Country or region',data=df.nlargest(10,'Freedom to make life choices'),ax=axes[1,1],palette='YlOrBr')
<AxesSubplot:xlabel='Freedom to make life choices', ylabel='Country or region'>
fig, axes = plt.subplots(nrows=1, ncols=2,constrained_layout=True,figsize=(10,4))
sns.barplot(x='Generosity' ,y='Country or region',data=df.nlargest(10,'Generosity'),ax=axes[0],palette='Spectral')
sns.barplot(x='Perceptions of corruption' ,y='Country or region',data=df.nlargest(10,'Perceptions of corruption'),ax=axes[1],palette='RdYlGn')
<AxesSubplot:xlabel='Perceptions of corruption', ylabel='Country or region'>
Now I want to give a category to each country as High,Mid and Low according to their happiness scores.Thus we have to find out the bound in which these categories shall lie in.
print('max:',df['Score'].max())
print('min:',df['Score'].min())
add=df['Score'].max()-df['Score'].min()
grp=round(add/3,3)
print('range difference:',(grp))
max: 7.769 min: 2.853 range difference: 1.639
low=df['Score'].min()+grp
mid=low+grp
print('upper bound of Low grp',low)
print('upper bound of Mid grp',mid)
print('upper bound of High grp','max:',df['Score'].max())
upper bound of Low grp 4.492 upper bound of Mid grp 6.131 upper bound of High grp max: 7.769
Finally adding a new column Category to the data set and distributing the levels High,Low,Mid.
cat=[]
for i in df.Score:
if(i>0 and i<low):
cat.append('Low')
elif(i>low and i<mid):
cat.append('Mid')
else:
cat.append('High')
df['Category']=cat
Also we will be styling the data set as a green zone and red zone .If the country belongs to the High category then it is under the green zone and if it is under the Mid or Low category it is going to be the red zone.
color = (df.Category == 'High' ).map({True: 'background-color: limegreen',False:'background-color: red'})
df.style.apply(lambda s: color)
| Overall rank | Country or region | Score | GDP per capita | Social support | Healthy life expectancy | Freedom to make life choices | Generosity | Perceptions of corruption | Category | |
|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | Finland | 7.769000 | 1.340000 | 1.587000 | 0.986000 | 0.596000 | 0.153000 | 0.393000 | High |
| 1 | 2 | Denmark | 7.600000 | 1.383000 | 1.573000 | 0.996000 | 0.592000 | 0.252000 | 0.410000 | High |
| 2 | 3 | Norway | 7.554000 | 1.488000 | 1.582000 | 1.028000 | 0.603000 | 0.271000 | 0.341000 | High |
| 3 | 4 | Iceland | 7.494000 | 1.380000 | 1.624000 | 1.026000 | 0.591000 | 0.354000 | 0.118000 | High |
| 4 | 5 | Netherlands | 7.488000 | 1.396000 | 1.522000 | 0.999000 | 0.557000 | 0.322000 | 0.298000 | High |
| 5 | 6 | Switzerland | 7.480000 | 1.452000 | 1.526000 | 1.052000 | 0.572000 | 0.263000 | 0.343000 | High |
| 6 | 7 | Sweden | 7.343000 | 1.387000 | 1.487000 | 1.009000 | 0.574000 | 0.267000 | 0.373000 | High |
| 7 | 8 | New Zealand | 7.307000 | 1.303000 | 1.557000 | 1.026000 | 0.585000 | 0.330000 | 0.380000 | High |
| 8 | 9 | Canada | 7.278000 | 1.365000 | 1.505000 | 1.039000 | 0.584000 | 0.285000 | 0.308000 | High |
| 9 | 10 | Austria | 7.246000 | 1.376000 | 1.475000 | 1.016000 | 0.532000 | 0.244000 | 0.226000 | High |
| 10 | 11 | Australia | 7.228000 | 1.372000 | 1.548000 | 1.036000 | 0.557000 | 0.332000 | 0.290000 | High |
| 11 | 12 | Costa Rica | 7.167000 | 1.034000 | 1.441000 | 0.963000 | 0.558000 | 0.144000 | 0.093000 | High |
| 12 | 13 | Israel | 7.139000 | 1.276000 | 1.455000 | 1.029000 | 0.371000 | 0.261000 | 0.082000 | High |
| 13 | 14 | Luxembourg | 7.090000 | 1.609000 | 1.479000 | 1.012000 | 0.526000 | 0.194000 | 0.316000 | High |
| 14 | 15 | United Kingdom | 7.054000 | 1.333000 | 1.538000 | 0.996000 | 0.450000 | 0.348000 | 0.278000 | High |
| 15 | 16 | Ireland | 7.021000 | 1.499000 | 1.553000 | 0.999000 | 0.516000 | 0.298000 | 0.310000 | High |
| 16 | 17 | Germany | 6.985000 | 1.373000 | 1.454000 | 0.987000 | 0.495000 | 0.261000 | 0.265000 | High |
| 17 | 18 | Belgium | 6.923000 | 1.356000 | 1.504000 | 0.986000 | 0.473000 | 0.160000 | 0.210000 | High |
| 18 | 19 | United States | 6.892000 | 1.433000 | 1.457000 | 0.874000 | 0.454000 | 0.280000 | 0.128000 | High |
| 19 | 20 | Czech Republic | 6.852000 | 1.269000 | 1.487000 | 0.920000 | 0.457000 | 0.046000 | 0.036000 | High |
| 20 | 21 | United Arab Emirates | 6.825000 | 1.503000 | 1.310000 | 0.825000 | 0.598000 | 0.262000 | 0.182000 | High |
| 21 | 22 | Malta | 6.726000 | 1.300000 | 1.520000 | 0.999000 | 0.564000 | 0.375000 | 0.151000 | High |
| 22 | 23 | Mexico | 6.595000 | 1.070000 | 1.323000 | 0.861000 | 0.433000 | 0.074000 | 0.073000 | High |
| 23 | 24 | France | 6.592000 | 1.324000 | 1.472000 | 1.045000 | 0.436000 | 0.111000 | 0.183000 | High |
| 24 | 25 | Taiwan | 6.446000 | 1.368000 | 1.430000 | 0.914000 | 0.351000 | 0.242000 | 0.097000 | High |
| 25 | 26 | Chile | 6.444000 | 1.159000 | 1.369000 | 0.920000 | 0.357000 | 0.187000 | 0.056000 | High |
| 26 | 27 | Guatemala | 6.436000 | 0.800000 | 1.269000 | 0.746000 | 0.535000 | 0.175000 | 0.078000 | High |
| 27 | 28 | Saudi Arabia | 6.375000 | 1.403000 | 1.357000 | 0.795000 | 0.439000 | 0.080000 | 0.132000 | High |
| 28 | 29 | Qatar | 6.374000 | 1.684000 | 1.313000 | 0.871000 | 0.555000 | 0.220000 | 0.167000 | High |
| 29 | 30 | Spain | 6.354000 | 1.286000 | 1.484000 | 1.062000 | 0.362000 | 0.153000 | 0.079000 | High |
| 30 | 31 | Panama | 6.321000 | 1.149000 | 1.442000 | 0.910000 | 0.516000 | 0.109000 | 0.054000 | High |
| 31 | 32 | Brazil | 6.300000 | 1.004000 | 1.439000 | 0.802000 | 0.390000 | 0.099000 | 0.086000 | High |
| 32 | 33 | Uruguay | 6.293000 | 1.124000 | 1.465000 | 0.891000 | 0.523000 | 0.127000 | 0.150000 | High |
| 33 | 34 | Singapore | 6.262000 | 1.572000 | 1.463000 | 1.141000 | 0.556000 | 0.271000 | 0.453000 | High |
| 34 | 35 | El Salvador | 6.253000 | 0.794000 | 1.242000 | 0.789000 | 0.430000 | 0.093000 | 0.074000 | High |
| 35 | 36 | Italy | 6.223000 | 1.294000 | 1.488000 | 1.039000 | 0.231000 | 0.158000 | 0.030000 | High |
| 36 | 37 | Bahrain | 6.199000 | 1.362000 | 1.368000 | 0.871000 | 0.536000 | 0.255000 | 0.110000 | High |
| 37 | 38 | Slovakia | 6.198000 | 1.246000 | 1.504000 | 0.881000 | 0.334000 | 0.121000 | 0.014000 | High |
| 38 | 39 | Trinidad & Tobago | 6.192000 | 1.231000 | 1.477000 | 0.713000 | 0.489000 | 0.185000 | 0.016000 | High |
| 39 | 40 | Poland | 6.182000 | 1.206000 | 1.438000 | 0.884000 | 0.483000 | 0.117000 | 0.050000 | High |
| 40 | 41 | Uzbekistan | 6.174000 | 0.745000 | 1.529000 | 0.756000 | 0.631000 | 0.322000 | 0.240000 | High |
| 41 | 42 | Lithuania | 6.149000 | 1.238000 | 1.515000 | 0.818000 | 0.291000 | 0.043000 | 0.042000 | High |
| 42 | 43 | Colombia | 6.125000 | 0.985000 | 1.410000 | 0.841000 | 0.470000 | 0.099000 | 0.034000 | Mid |
| 43 | 44 | Slovenia | 6.118000 | 1.258000 | 1.523000 | 0.953000 | 0.564000 | 0.144000 | 0.057000 | Mid |
| 44 | 45 | Nicaragua | 6.105000 | 0.694000 | 1.325000 | 0.835000 | 0.435000 | 0.200000 | 0.127000 | Mid |
| 45 | 46 | Kosovo | 6.100000 | 0.882000 | 1.232000 | 0.758000 | 0.489000 | 0.262000 | 0.006000 | Mid |
| 46 | 47 | Argentina | 6.086000 | 1.092000 | 1.432000 | 0.881000 | 0.471000 | 0.066000 | 0.050000 | Mid |
| 47 | 48 | Romania | 6.070000 | 1.162000 | 1.232000 | 0.825000 | 0.462000 | 0.083000 | 0.005000 | Mid |
| 48 | 49 | Cyprus | 6.046000 | 1.263000 | 1.223000 | 1.042000 | 0.406000 | 0.190000 | 0.041000 | Mid |
| 49 | 50 | Ecuador | 6.028000 | 0.912000 | 1.312000 | 0.868000 | 0.498000 | 0.126000 | 0.087000 | Mid |
| 50 | 51 | Kuwait | 6.021000 | 1.500000 | 1.319000 | 0.808000 | 0.493000 | 0.142000 | 0.097000 | Mid |
| 51 | 52 | Thailand | 6.008000 | 1.050000 | 1.409000 | 0.828000 | 0.557000 | 0.359000 | 0.028000 | Mid |
| 52 | 53 | Latvia | 5.940000 | 1.187000 | 1.465000 | 0.812000 | 0.264000 | 0.075000 | 0.064000 | Mid |
| 53 | 54 | South Korea | 5.895000 | 1.301000 | 1.219000 | 1.036000 | 0.159000 | 0.175000 | 0.056000 | Mid |
| 54 | 55 | Estonia | 5.893000 | 1.237000 | 1.528000 | 0.874000 | 0.495000 | 0.103000 | 0.161000 | Mid |
| 55 | 56 | Jamaica | 5.890000 | 0.831000 | 1.478000 | 0.831000 | 0.490000 | 0.107000 | 0.028000 | Mid |
| 56 | 57 | Mauritius | 5.888000 | 1.120000 | 1.402000 | 0.798000 | 0.498000 | 0.215000 | 0.060000 | Mid |
| 57 | 58 | Japan | 5.886000 | 1.327000 | 1.419000 | 1.088000 | 0.445000 | 0.069000 | 0.140000 | Mid |
| 58 | 59 | Honduras | 5.860000 | 0.642000 | 1.236000 | 0.828000 | 0.507000 | 0.246000 | 0.078000 | Mid |
| 59 | 60 | Kazakhstan | 5.809000 | 1.173000 | 1.508000 | 0.729000 | 0.410000 | 0.146000 | 0.096000 | Mid |
| 60 | 61 | Bolivia | 5.779000 | 0.776000 | 1.209000 | 0.706000 | 0.511000 | 0.137000 | 0.064000 | Mid |
| 61 | 62 | Hungary | 5.758000 | 1.201000 | 1.410000 | 0.828000 | 0.199000 | 0.081000 | 0.020000 | Mid |
| 62 | 63 | Paraguay | 5.743000 | 0.855000 | 1.475000 | 0.777000 | 0.514000 | 0.184000 | 0.080000 | Mid |
| 63 | 64 | Northern Cyprus | 5.718000 | 1.263000 | 1.252000 | 1.042000 | 0.417000 | 0.191000 | 0.162000 | Mid |
| 64 | 65 | Peru | 5.697000 | 0.960000 | 1.274000 | 0.854000 | 0.455000 | 0.083000 | 0.027000 | Mid |
| 65 | 66 | Portugal | 5.693000 | 1.221000 | 1.431000 | 0.999000 | 0.508000 | 0.047000 | 0.025000 | Mid |
| 66 | 67 | Pakistan | 5.653000 | 0.677000 | 0.886000 | 0.535000 | 0.313000 | 0.220000 | 0.098000 | Mid |
| 67 | 68 | Russia | 5.648000 | 1.183000 | 1.452000 | 0.726000 | 0.334000 | 0.082000 | 0.031000 | Mid |
| 68 | 69 | Philippines | 5.631000 | 0.807000 | 1.293000 | 0.657000 | 0.558000 | 0.117000 | 0.107000 | Mid |
| 69 | 70 | Serbia | 5.603000 | 1.004000 | 1.383000 | 0.854000 | 0.282000 | 0.137000 | 0.039000 | Mid |
| 70 | 71 | Moldova | 5.529000 | 0.685000 | 1.328000 | 0.739000 | 0.245000 | 0.181000 | 0.000000 | Mid |
| 71 | 72 | Libya | 5.525000 | 1.044000 | 1.303000 | 0.673000 | 0.416000 | 0.133000 | 0.152000 | Mid |
| 72 | 73 | Montenegro | 5.523000 | 1.051000 | 1.361000 | 0.871000 | 0.197000 | 0.142000 | 0.080000 | Mid |
| 73 | 74 | Tajikistan | 5.467000 | 0.493000 | 1.098000 | 0.718000 | 0.389000 | 0.230000 | 0.144000 | Mid |
| 74 | 75 | Croatia | 5.432000 | 1.155000 | 1.266000 | 0.914000 | 0.296000 | 0.119000 | 0.022000 | Mid |
| 75 | 76 | Hong Kong | 5.430000 | 1.438000 | 1.277000 | 1.122000 | 0.440000 | 0.258000 | 0.287000 | Mid |
| 76 | 77 | Dominican Republic | 5.425000 | 1.015000 | 1.401000 | 0.779000 | 0.497000 | 0.113000 | 0.101000 | Mid |
| 77 | 78 | Bosnia and Herzegovina | 5.386000 | 0.945000 | 1.212000 | 0.845000 | 0.212000 | 0.263000 | 0.006000 | Mid |
| 78 | 79 | Turkey | 5.373000 | 1.183000 | 1.360000 | 0.808000 | 0.195000 | 0.083000 | 0.106000 | Mid |
| 79 | 80 | Malaysia | 5.339000 | 1.221000 | 1.171000 | 0.828000 | 0.508000 | 0.260000 | 0.024000 | Mid |
| 80 | 81 | Belarus | 5.323000 | 1.067000 | 1.465000 | 0.789000 | 0.235000 | 0.094000 | 0.142000 | Mid |
| 81 | 82 | Greece | 5.287000 | 1.181000 | 1.156000 | 0.999000 | 0.067000 | 0.000000 | 0.034000 | Mid |
| 82 | 83 | Mongolia | 5.285000 | 0.948000 | 1.531000 | 0.667000 | 0.317000 | 0.235000 | 0.038000 | Mid |
| 83 | 84 | North Macedonia | 5.274000 | 0.983000 | 1.294000 | 0.838000 | 0.345000 | 0.185000 | 0.034000 | Mid |
| 84 | 85 | Nigeria | 5.265000 | 0.696000 | 1.111000 | 0.245000 | 0.426000 | 0.215000 | 0.041000 | Mid |
| 85 | 86 | Kyrgyzstan | 5.261000 | 0.551000 | 1.438000 | 0.723000 | 0.508000 | 0.300000 | 0.023000 | Mid |
| 86 | 87 | Turkmenistan | 5.247000 | 1.052000 | 1.538000 | 0.657000 | 0.394000 | 0.244000 | 0.028000 | Mid |
| 87 | 88 | Algeria | 5.211000 | 1.002000 | 1.160000 | 0.785000 | 0.086000 | 0.073000 | 0.114000 | Mid |
| 88 | 89 | Morocco | 5.208000 | 0.801000 | 0.782000 | 0.782000 | 0.418000 | 0.036000 | 0.076000 | Mid |
| 89 | 90 | Azerbaijan | 5.208000 | 1.043000 | 1.147000 | 0.769000 | 0.351000 | 0.035000 | 0.182000 | Mid |
| 90 | 91 | Lebanon | 5.197000 | 0.987000 | 1.224000 | 0.815000 | 0.216000 | 0.166000 | 0.027000 | Mid |
| 91 | 92 | Indonesia | 5.192000 | 0.931000 | 1.203000 | 0.660000 | 0.491000 | 0.498000 | 0.028000 | Mid |
| 92 | 93 | China | 5.191000 | 1.029000 | 1.125000 | 0.893000 | 0.521000 | 0.058000 | 0.100000 | Mid |
| 93 | 94 | Vietnam | 5.175000 | 0.741000 | 1.346000 | 0.851000 | 0.543000 | 0.147000 | 0.073000 | Mid |
| 94 | 95 | Bhutan | 5.082000 | 0.813000 | 1.321000 | 0.604000 | 0.457000 | 0.370000 | 0.167000 | Mid |
| 95 | 96 | Cameroon | 5.044000 | 0.549000 | 0.910000 | 0.331000 | 0.381000 | 0.187000 | 0.037000 | Mid |
| 96 | 97 | Bulgaria | 5.011000 | 1.092000 | 1.513000 | 0.815000 | 0.311000 | 0.081000 | 0.004000 | Mid |
| 97 | 98 | Ghana | 4.996000 | 0.611000 | 0.868000 | 0.486000 | 0.381000 | 0.245000 | 0.040000 | Mid |
| 98 | 99 | Ivory Coast | 4.944000 | 0.569000 | 0.808000 | 0.232000 | 0.352000 | 0.154000 | 0.090000 | Mid |
| 99 | 100 | Nepal | 4.913000 | 0.446000 | 1.226000 | 0.677000 | 0.439000 | 0.285000 | 0.089000 | Mid |
| 100 | 101 | Jordan | 4.906000 | 0.837000 | 1.225000 | 0.815000 | 0.383000 | 0.110000 | 0.130000 | Mid |
| 101 | 102 | Benin | 4.883000 | 0.393000 | 0.437000 | 0.397000 | 0.349000 | 0.175000 | 0.082000 | Mid |
| 102 | 103 | Congo (Brazzaville) | 4.812000 | 0.673000 | 0.799000 | 0.508000 | 0.372000 | 0.105000 | 0.093000 | Mid |
| 103 | 104 | Gabon | 4.799000 | 1.057000 | 1.183000 | 0.571000 | 0.295000 | 0.043000 | 0.055000 | Mid |
| 104 | 105 | Laos | 4.796000 | 0.764000 | 1.030000 | 0.551000 | 0.547000 | 0.266000 | 0.164000 | Mid |
| 105 | 106 | South Africa | 4.722000 | 0.960000 | 1.351000 | 0.469000 | 0.389000 | 0.130000 | 0.055000 | Mid |
| 106 | 107 | Albania | 4.719000 | 0.947000 | 0.848000 | 0.874000 | 0.383000 | 0.178000 | 0.027000 | Mid |
| 107 | 108 | Venezuela | 4.707000 | 0.960000 | 1.427000 | 0.805000 | 0.154000 | 0.064000 | 0.047000 | Mid |
| 108 | 109 | Cambodia | 4.700000 | 0.574000 | 1.122000 | 0.637000 | 0.609000 | 0.232000 | 0.062000 | Mid |
| 109 | 110 | Palestinian Territories | 4.696000 | 0.657000 | 1.247000 | 0.672000 | 0.225000 | 0.103000 | 0.066000 | Mid |
| 110 | 111 | Senegal | 4.681000 | 0.450000 | 1.134000 | 0.571000 | 0.292000 | 0.153000 | 0.072000 | Mid |
| 111 | 112 | Somalia | 4.668000 | 0.000000 | 0.698000 | 0.268000 | 0.559000 | 0.243000 | 0.270000 | Mid |
| 112 | 113 | Namibia | 4.639000 | 0.879000 | 1.313000 | 0.477000 | 0.401000 | 0.070000 | 0.056000 | Mid |
| 113 | 114 | Niger | 4.628000 | 0.138000 | 0.774000 | 0.366000 | 0.318000 | 0.188000 | 0.102000 | Mid |
| 114 | 115 | Burkina Faso | 4.587000 | 0.331000 | 1.056000 | 0.380000 | 0.255000 | 0.177000 | 0.113000 | Mid |
| 115 | 116 | Armenia | 4.559000 | 0.850000 | 1.055000 | 0.815000 | 0.283000 | 0.095000 | 0.064000 | Mid |
| 116 | 117 | Iran | 4.548000 | 1.100000 | 0.842000 | 0.785000 | 0.305000 | 0.270000 | 0.125000 | Mid |
| 117 | 118 | Guinea | 4.534000 | 0.380000 | 0.829000 | 0.375000 | 0.332000 | 0.207000 | 0.086000 | Mid |
| 118 | 119 | Georgia | 4.519000 | 0.886000 | 0.666000 | 0.752000 | 0.346000 | 0.043000 | 0.164000 | Mid |
| 119 | 120 | Gambia | 4.516000 | 0.308000 | 0.939000 | 0.428000 | 0.382000 | 0.269000 | 0.167000 | Mid |
| 120 | 121 | Kenya | 4.509000 | 0.512000 | 0.983000 | 0.581000 | 0.431000 | 0.372000 | 0.053000 | Mid |
| 121 | 122 | Mauritania | 4.490000 | 0.570000 | 1.167000 | 0.489000 | 0.066000 | 0.106000 | 0.088000 | Low |
| 122 | 123 | Mozambique | 4.466000 | 0.204000 | 0.986000 | 0.390000 | 0.494000 | 0.197000 | 0.138000 | Low |
| 123 | 124 | Tunisia | 4.461000 | 0.921000 | 1.000000 | 0.815000 | 0.167000 | 0.059000 | 0.055000 | Low |
| 124 | 125 | Bangladesh | 4.456000 | 0.562000 | 0.928000 | 0.723000 | 0.527000 | 0.166000 | 0.143000 | Low |
| 125 | 126 | Iraq | 4.437000 | 1.043000 | 0.980000 | 0.574000 | 0.241000 | 0.148000 | 0.089000 | Low |
| 126 | 127 | Congo (Kinshasa) | 4.418000 | 0.094000 | 1.125000 | 0.357000 | 0.269000 | 0.212000 | 0.053000 | Low |
| 127 | 128 | Mali | 4.390000 | 0.385000 | 1.105000 | 0.308000 | 0.327000 | 0.153000 | 0.052000 | Low |
| 128 | 129 | Sierra Leone | 4.374000 | 0.268000 | 0.841000 | 0.242000 | 0.309000 | 0.252000 | 0.045000 | Low |
| 129 | 130 | Sri Lanka | 4.366000 | 0.949000 | 1.265000 | 0.831000 | 0.470000 | 0.244000 | 0.047000 | Low |
| 130 | 131 | Myanmar | 4.360000 | 0.710000 | 1.181000 | 0.555000 | 0.525000 | 0.566000 | 0.172000 | Low |
| 131 | 132 | Chad | 4.350000 | 0.350000 | 0.766000 | 0.192000 | 0.174000 | 0.198000 | 0.078000 | Low |
| 132 | 133 | Ukraine | 4.332000 | 0.820000 | 1.390000 | 0.739000 | 0.178000 | 0.187000 | 0.010000 | Low |
| 133 | 134 | Ethiopia | 4.286000 | 0.336000 | 1.033000 | 0.532000 | 0.344000 | 0.209000 | 0.100000 | Low |
| 134 | 135 | Swaziland | 4.212000 | 0.811000 | 1.149000 | 0.000000 | 0.313000 | 0.074000 | 0.135000 | Low |
| 135 | 136 | Uganda | 4.189000 | 0.332000 | 1.069000 | 0.443000 | 0.356000 | 0.252000 | 0.060000 | Low |
| 136 | 137 | Egypt | 4.166000 | 0.913000 | 1.039000 | 0.644000 | 0.241000 | 0.076000 | 0.067000 | Low |
| 137 | 138 | Zambia | 4.107000 | 0.578000 | 1.058000 | 0.426000 | 0.431000 | 0.247000 | 0.087000 | Low |
| 138 | 139 | Togo | 4.085000 | 0.275000 | 0.572000 | 0.410000 | 0.293000 | 0.177000 | 0.085000 | Low |
| 139 | 140 | India | 4.015000 | 0.755000 | 0.765000 | 0.588000 | 0.498000 | 0.200000 | 0.085000 | Low |
| 140 | 141 | Liberia | 3.975000 | 0.073000 | 0.922000 | 0.443000 | 0.370000 | 0.233000 | 0.033000 | Low |
| 141 | 142 | Comoros | 3.973000 | 0.274000 | 0.757000 | 0.505000 | 0.142000 | 0.275000 | 0.078000 | Low |
| 142 | 143 | Madagascar | 3.933000 | 0.274000 | 0.916000 | 0.555000 | 0.148000 | 0.169000 | 0.041000 | Low |
| 143 | 144 | Lesotho | 3.802000 | 0.489000 | 1.169000 | 0.168000 | 0.359000 | 0.107000 | 0.093000 | Low |
| 144 | 145 | Burundi | 3.775000 | 0.046000 | 0.447000 | 0.380000 | 0.220000 | 0.176000 | 0.180000 | Low |
| 145 | 146 | Zimbabwe | 3.663000 | 0.366000 | 1.114000 | 0.433000 | 0.361000 | 0.151000 | 0.089000 | Low |
| 146 | 147 | Haiti | 3.597000 | 0.323000 | 0.688000 | 0.449000 | 0.026000 | 0.419000 | 0.110000 | Low |
| 147 | 148 | Botswana | 3.488000 | 1.041000 | 1.145000 | 0.538000 | 0.455000 | 0.025000 | 0.100000 | Low |
| 148 | 149 | Syria | 3.462000 | 0.619000 | 0.378000 | 0.440000 | 0.013000 | 0.331000 | 0.141000 | Low |
| 149 | 150 | Malawi | 3.410000 | 0.191000 | 0.560000 | 0.495000 | 0.443000 | 0.218000 | 0.089000 | Low |
| 150 | 151 | Yemen | 3.380000 | 0.287000 | 1.163000 | 0.463000 | 0.143000 | 0.108000 | 0.077000 | Low |
| 151 | 152 | Rwanda | 3.334000 | 0.359000 | 0.711000 | 0.614000 | 0.555000 | 0.217000 | 0.411000 | Low |
| 152 | 153 | Tanzania | 3.231000 | 0.476000 | 0.885000 | 0.499000 | 0.417000 | 0.276000 | 0.147000 | Low |
| 153 | 154 | Afghanistan | 3.203000 | 0.350000 | 0.517000 | 0.361000 | 0.000000 | 0.158000 | 0.025000 | Low |
| 154 | 155 | Central African Republic | 3.083000 | 0.026000 | 0.000000 | 0.105000 | 0.225000 | 0.235000 | 0.035000 | Low |
| 155 | 156 | South Sudan | 2.853000 | 0.306000 | 0.575000 | 0.295000 | 0.010000 | 0.202000 | 0.091000 | Low |
Now since I am from India I would like to see my countries position on the list and also checkout some other countries where people from India usually settle for economic benefits. So lets check them out:
df.loc[df['Country or region']=='India']
| Overall rank | Country or region | Score | GDP per capita | Social support | Healthy life expectancy | Freedom to make life choices | Generosity | Perceptions of corruption | Category | |
|---|---|---|---|---|---|---|---|---|---|---|
| 139 | 140 | India | 4.015 | 0.755 | 0.765 | 0.588 | 0.498 | 0.2 | 0.085 | Low |
Now since I am from India I would like to see my countries position on the list and also checkout some other countries where people from India usually settle for economic benefits. So lets check them out:
data={
'Country or region':['Canada','US','UK','India'],
'Score':[7.278,6.892,7.054,4.015],
'GDP per capita':[1.365,1.433,1.333,0.755],
'Social support':[1.505,1.457,1.538,0.765],
'Healthy life expectancy':[1.039,0.874,0.996,0.588],
'Freedom to make life choices':[0.584,0.454,0.45,0.498],
'Generosity':[0.285,0.28,0.348,0.2],
'Perceptions of corruption':[0.308,0.128,0.278,0.085]
}
d=pd.DataFrame(data)
d
| Country or region | Score | GDP per capita | Social support | Healthy life expectancy | Freedom to make life choices | Generosity | Perceptions of corruption | |
|---|---|---|---|---|---|---|---|---|
| 0 | Canada | 7.278 | 1.365 | 1.505 | 1.039 | 0.584 | 0.285 | 0.308 |
| 1 | US | 6.892 | 1.433 | 1.457 | 0.874 | 0.454 | 0.280 | 0.128 |
| 2 | UK | 7.054 | 1.333 | 1.538 | 0.996 | 0.450 | 0.348 | 0.278 |
| 3 | India | 4.015 | 0.755 | 0.765 | 0.588 | 0.498 | 0.200 | 0.085 |
Social Support vs GDP per capita vs Healthy life expectancy
ax = d.plot(y="Social support", x="Country or region", kind="bar",color='C3')
d.plot(y="GDP per capita", x="Country or region", kind="bar", ax=ax, color="C1")
d.plot(y="Healthy life expectancy", x="Country or region", kind="bar", ax=ax, color="C2")
plt.show()
Freedom to make life choices vs Generosity vs Corruption
ax = d.plot(y="Freedom to make life choices", x="Country or region", kind="bar",color='C3')
d.plot(y="Generosity", x="Country or region", kind="bar", ax=ax, color="C1",)
d.plot(y="Perceptions of corruption", x="Country or region", kind="bar", ax=ax, color="C2",)
plt.show()
Geographic Visualization of Happiness Score
conda install -c plotly plotly
Collecting package metadata (current_repodata.json): ...working... done
Solving environment: ...working... done
## Package Plan ##
environment location: C:\Users\lenovo\anaconda3
added / updated specs:
- plotly
The following packages will be downloaded:
package | build
---------------------------|-----------------
conda-4.10.3 | py38haa95532_0 2.9 MB
plotly-5.1.0 | py_0 6.7 MB plotly
tenacity-7.0.0 | py38haa95532_0 33 KB
------------------------------------------------------------
Total: 9.6 MB
The following NEW packages will be INSTALLED:
plotly plotly/noarch::plotly-5.1.0-py_0
tenacity pkgs/main/win-64::tenacity-7.0.0-py38haa95532_0
The following packages will be UPDATED:
conda 4.10.1-py38haa95532_1 --> 4.10.3-py38haa95532_0
Downloading and Extracting Packages
conda-4.10.3 | 2.9 MB | | 0%
conda-4.10.3 | 2.9 MB | 3 | 3%
conda-4.10.3 | 2.9 MB | # | 10%
conda-4.10.3 | 2.9 MB | #7 | 18%
conda-4.10.3 | 2.9 MB | ##5 | 26%
conda-4.10.3 | 2.9 MB | ###2 | 32%
conda-4.10.3 | 2.9 MB | ###9 | 39%
conda-4.10.3 | 2.9 MB | ####6 | 46%
conda-4.10.3 | 2.9 MB | #####3 | 54%
conda-4.10.3 | 2.9 MB | ######1 | 62%
conda-4.10.3 | 2.9 MB | ######8 | 69%
conda-4.10.3 | 2.9 MB | #######5 | 76%
conda-4.10.3 | 2.9 MB | ########2 | 83%
conda-4.10.3 | 2.9 MB | ######### | 90%
conda-4.10.3 | 2.9 MB | #########7 | 97%
conda-4.10.3 | 2.9 MB | ########## | 100%
tenacity-7.0.0 | 33 KB | | 0%
tenacity-7.0.0 | 33 KB | ####8 | 49%
tenacity-7.0.0 | 33 KB | ########## | 100%
plotly-5.1.0 | 6.7 MB | | 0%
plotly-5.1.0 | 6.7 MB | ########## | 100%
plotly-5.1.0 | 6.7 MB | ########## | 100%
Preparing transaction: ...working... done
Verifying transaction: ...working... done
Executing transaction: ...working... done
Note: you may need to restart the kernel to use updated packages.
import plotly.graph_objs as go
from plotly.offline import iplot
data = dict(type = 'choropleth',
locations = df['Country or region'],
locationmode = 'country names',
colorscale='RdYlGn',
z = df['Score'],
text = df['Country or region'],
colorbar = {'title':'Happiness Score'})
layout = dict(title = 'Geographical Visualization of Happiness Score',
geo = dict(showframe = True, projection = {'type': 'azimuthal equal area'}))
choromap3 = go.Figure(data = [data], layout=layout)
iplot(choromap3)